package com.george.shiro.config;

import com.george.shiro.interceptor.RememberAuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>
 *  声明一个web配置类，添加一个拦截器配置，
 *  注册一个记住登录状态的拦截器
 * </p>
 *
 * @author GeorgeChan 2019/5/24 13:54
 * @version 1.0
 * @since jdk1.8
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private RememberAuthenticationInterceptor rememberAuthenticationInterceptor;


    /**
     * 添加令牌处理拦截器，检查请求头是否带有效的令牌。
     * addInterceptor 可以加入多个拦截器组成一个拦截器链
     * addPathPatterns 用于添加拦截规则
     * excludePathPatterns 用户排除拦截规则
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(rememberAuthenticationInterceptor)
                .excludePathPatterns("/passport/**", "/error/**", "/assets/**", "favicon.ico")
                .addPathPatterns("/**");
    }
}
